import { Sequelize } from "sequelize";
const env = process.env;

const sequelize = new Sequelize(env.Y_DB_DATABASE as string, env.Y_DB_USERNAME as string, env.Y_DB_PASSWORD, {
  host: env.DB_HOST,
  dialect: "mysql",
  logging: false,
  timezone: "+08:00",
  dialectOptions: {
    dateStrings: true,
    typeCast: true,
  },
});

(async () => {
  try {
    await sequelize.authenticate();
    console.log("数据库连接成功");
  } catch (error) {
    console.error("Unable to connect to the database:", error);
  }
})();

export default sequelize;
